<template>
	<view :class="['main_style','main_bg']">
		<block v-for="(item,index) in list" :key="index">
			<view class="item_class" @click="gotoMiniProgram(item)">
				<image class="left_class" :src="cacheCmage(item.wx_icon)"></image>
				<view class="middle_class">
					<view class="middle_top">{{item.wx_title}}</view>
					<view class="middle_bottom">{{item.wx_subtitle}}</view>
				</view>
			</view>
		</block>
	</view>
</template>

<script>
	var _this = null;
	export default {
		data() {
			return {
				list:[],
				reload:''
			}
		},
		onLoad() {
			_this = this;
			this.fetchData();
		},
		methods: {
			gotoMiniProgram(item){
				console.log(item);
				wx.navigateToMiniProgram({
				    appId: item.wx_app_id,
				    path: item.path,
				    envVersion: 'release',// 打开正式版
				    success(res) {
				         // 打开成功
						 console.log(res);
				    },
				    fail: function (err) {
				      console.log(err);
				    }
				 })
			},
			cacheCmage(url) {
				var local_image = this.$request.cache_image({
					image_url: url,
					call_back:(data)=> {
						this.reload = data;
					}
				})
				if (this.$u.test.isEmpty(local_image)) {
					return url;
				}
				return local_image;
			},
			
			fetchData(){
				this.$request.post({
					url: "/mSystem/miniList",
					data:{"wx_app_id":this.$config.wx_app_id},
					// needEncryption:true,
					success:(res)=> {
						uni.hideLoading();
						console.log(res);
						this.list = res;
					},
					fail(failed) {
						uni.hideLoading();
					}
				});
			}
		}
	}
</script>

<style lang="stylus" scoped>
	
	.main_bg{
		background-color #eee;
	}
	
	.item_class{
		display flex;
		margin-top 20rpx;
		// margin-bottom 20rpx;
		margin-left 20rpx;
		margin-right 20rpx;
		height 130rpx;
		background-color #fff;
		border-radius 10rpx;
		justify-content space-between;
		align-items center;
		
		.left_class{
			margin-left 33rpx;
			width 64rpx;
			height 64rpx;
			background-color rgba(0, 0, 0, 0);
			font-size 30rpx;
			font-weight bold;
		}
		
		.middle_class{
			display flex;
			flex-direction column;
			margin-left 20rpx;
			text-align left;
			flex 1;
			
			.middle_top {
				font-size 28rpx;
				font-weight bold;
				line-height 40rpx;
				height 40rpx;
			}
			
			.middle_bottom {
				// background-color #000000;
				color #999999;
				font-size 22rpx;
				line-height 30rpx;
				height 30rpx;
			}
		}
	}
</style>
